﻿using Autofac.Builder;

namespace YWM.DependencyInjection.Extensions
{
    internal static class DependencyExtensions
    {
        /// <summary>
        /// 注册生命周期
        /// </summary>
        /// <typeparam name="TLimit"></typeparam>
        /// <typeparam name="TActivatorData"></typeparam>
        /// <typeparam name="TRegistrationStyle"></typeparam>
        /// <param name="registrationBuilder"></param>
        /// <param name="dependencyLifeTime"></param>
        /// <returns></returns>
        internal static IRegistrationBuilder<TLimit, TActivatorData, TRegistrationStyle> RegisterLifeTime<TLimit, TActivatorData, TRegistrationStyle>(this IRegistrationBuilder<TLimit, TActivatorData, TRegistrationStyle> registrationBuilder, DependencyLifeTime dependencyLifeTime)
        {
            switch (dependencyLifeTime)
            {
                case DependencyLifeTime.Transient:
                    registrationBuilder.InstancePerDependency();
                    break;
                case DependencyLifeTime.Scoped:
                    registrationBuilder.InstancePerLifetimeScope();
                    break;
                case DependencyLifeTime.Singleton:
                    registrationBuilder.SingleInstance();
                    break;
            }
            return registrationBuilder;
        }
    }
}
